<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ page import="javax.portlet.*"%>
<%@page import ="rai.dto.*" %>
<%@page import ="rai.dao.*" %>
<%@page import = "java.util.*" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>

<portlet:defineObjects />
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Personal Information Tracking System</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<script type="text/javascript" src='<%=request.getContextPath() +"/js/calendarDateInput.js"%>'></script>
<script type="text/javascript">
    function getForm(namespace, name) {
        return document.forms[namespace + name];
    }
    function back_to_manacc(namespace, name) {
		var frm = getForm(namespace, name);
		frm.txtAction.value = "back_to_manacc";
		frm.submit();
	}
    function submitForm(namespace, name) {
        var frm = getForm(namespace, name);
        frm.txtAction.value = "register";
        frm.submit();
    }
    
	function getCompName(namespace, name){
		
		var frm = getForm(namespace, name);
		frm.submit();
	}
	function asynchGet(updateURL,lstresponse){
		 
	    if (window.XMLHttpRequest) {
	        portletReq = new XMLHttpRequest();
	    } else if (window.ActiveXObject) {
	        portletReq = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  // alert(updateURL+" "+ lstresponse);
	    portletReq.onreadystatechange = function() {processReqChange(lstresponse);};
	    
	    portletReq.open("GET", updateURL, true);
	    //alert(updateURL);
	    portletReq.send(null);
	}
	function processReqChange(lstresponse) {
		//alert(portletReq.status+" "+portletReq.readyState);
		//alert(lstresponse);
	    if (portletReq.readyState == 4) {
	        if (portletReq.status == 200) {
	            // process response
	            //alert("proccess");
	            displayDepartment(lstresponse);
	        }
	    }
	}
	function selectComp(evt,lstresponse) {
		
	    evt = (evt) ? evt : ((window.event) ? window.event : null);
	    if (evt) {
	    	
	        var select = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	        if (select && select.options.length > 1) {
	        	 //alert(lstresponse);
	        	asynchGet('<%=request.getContextPath()%>'+"/AddActionServlet?lstComp=" + select.value+"&name="+lstresponse,lstresponse);
	        }
	    }
	}
		
	function displayDepartment(lstresponse) {
	    // substitute new invoice HTML content into "portletcontent" <div> tag
	    //alert(lstid);
	   // alert(lstresponse);
	    //alert("result"+portletReq.responseText);
	    var div = document.getElementById(lstresponse);
	    //alert(portletReq.responseText);
	    div.innerHTML = "";
	   	var result = portletReq.responseText.split('######');
	    div.innerHTML = result[0];
	    
	}
	function init() {
		asynchGet('<%= request.getContextPath()+"/AddActionServlet?lstComp=1&name=lstDept"%>','lstDept');
		
		
	}
</script>


<link href='<%=request.getContextPath()+"css/style.css"%>' rel="stylesheet" type="text/css" media="screen" /></head>

<body onload="init();">
<form name="<portlet:namespace/>registerForm" action="<portlet:actionURL/>" method="POST">
	<input type="hidden" name="txtAction" />
<table align="center">
	<tr class="title">
			<td>	
					<h1><font color="blue">Personal information tracking system</font></h1>
					<p>exploit the value of data</p>
					<hr />
			</td>
	</tr>
	
	<tr>				
		<td>
			<table border="1" width="100%" align="center" cellpadding="2" cellspacing="2">
				<tr>
					<td colspan="2"><h2 class="title" align="center"><font color="orange">AddACC</font></h2></td>
				</tr>
				<tr>
					<td><em>Account Information</em></td>
				</tr>
				<tr>
					<td>
					<table border="1" width="100%">
						<tr>
							<td>UserName</td>
							<td><input name="txtUserName" type="text" 
							    value='${sessionScope.name}' /></td>
						</tr>
						<tr>
							<td>Password</td>
							<td><input name="txtPassword" type="password" /></td>
						</tr>
						
					</table>
					</td>
				</tr>
				<tr>
					<td><em>Employee Information</em></td>
				</tr>
				<tr>
					<td>
						<table border="1" width="100%">
							<tr>
								<td>Employee Name</td>
								<td><input name="txtEmpName" type="text" 
								    value='${sessionScope.regEmpName}' /></td>
							</tr>
							<tr>
								<td>Birthday</td>
								<td>
								<%String path= request.getContextPath(); %>
								<script>DateInput('txtBirthday',true,'DD/MM/YYYY','<%=path%>','${sessionScope.regBirthday}');</script></td> 
							</tr>
							<tr>
								<td>Address</td>
								<td><input name="txtEmpAddress" type="text" 
									value = '${sessionScope.regAddress}'/></td>
							</tr>
							<tr>
								<td>Email</td>
								<td><input name="txtEmpEmail" type="text" 
									value = '${sessionScope.regEmail}'/></td>
							</tr>
							<tr>
								<td>Phone</td>
								<td><input name="txtEmpPhone" type="text" 
									value = '${sessionScope.regPhone}'/></td>
							</tr>
							<tr>
								<td>Gender</td>
								<td>
									<input name="radioGender" type="radio" value="1" CHECKED/>Male
									<input name="radioGender" type="radio" value="0"/>Female
								</td>

							</tr>
							<tr>
							  
							  <td align="left" valign="middle">Company
								  <select name="lstCompAdd" onchange ="selectComp(event,'lstDept')">
								  		<%SearchInfoDAO daoSearch = new SearchInfoDAO();
								  		  List<CompanyDTO> lst_comp = daoSearch.getComp();
								  		  for(int i=1;i<lst_comp.size();i++) {
								  		  	CompanyDTO temp = lst_comp.get(i);
								  		%>
								  			<option value="<%=temp.getId() %>"><%=temp.getSname() %></option>
								  		<%} %>
								  	</select>
							
							 </td>
							   <td colspan="2" align="left" valign="middle">Department
							   <div id="lstDept"></div>
							   </td>
							  
								   
						  </tr>	
						</table>
					</td>
				</tr>
				<tr>
							<td>	<input type="button" name="btnRegister" value="Add" 
									onclick="submitForm('<portlet:namespace/>','registerForm')" />
									<input type="button" name="btnCancel" value="Cancel" 
									onclick="back_to_manacc('<portlet:namespace/>','registerForm')" />
									<p style=""><b><font color="red">${sessionScope.errorMess}</font></b></p>
							</td>
							
						</tr>
			</table>
		</td>
	</tr>
	
	<tr>
		<td colspan="2">
			<div style="clear: both;">&nbsp;</div>

			<div id="footer"><p>Development by HCMUT-Group3.</p>
			</div>
		</td>
	</tr>
</table>
</form>
</body>

